/*
* 设备运行状态图
* */
import echart from 'echarts'

const deviceLife = (title, data) => {
  data[0].itemStyle = {
    normal: {
      color: new echart.graphic.LinearGradient(0, 0, 0, 1, [
        {
          offset: 0,
          color: '#91CEF8'
        },
        {
          offset: 1,
          color: '#91CEF8'
        }
      ])
    }
  }

  data[1].itemStyle = {
    normal: {
      color: new echart.graphic.LinearGradient(1, 0, 0, 1, [
        {
          offset: 0,
          color: '#2CA5FA'
        },
        {
          offset: 1,
          color: '#00E9FF'
        }
      ])
    }
  }

  let option = {
    title: {
      text: title,
      top: '8%',
      left: '10%',
      textStyle: {
        color: '#50E3C2'
      }
    },
    legend: {
      orient: 'vertical',
      right: '0',
      bottom: '40%',
      data: data,
      textStyle: {
        color: '#fff'
      }
    },
    series: [
      {
        name: '设备情况',
        type: 'pie',
        radius: ['10%', '50%'],
        center: ['35%', '55%'],
        data: data,
        itemStyle: {
          emphasis: {
            shadowBlur: 10,
            shadowOffsetX: 0,
            shadowColor: 'rgba(0, 0, 0, 0.5)'
          }
        },
        label: {
          normal: {
            position: 'inside',
            show: true,
            formatter: '{d}%'
          }
        }
      }
    ]
  }
  let device = echart.init(document.getElementById('deviceLife'))
  device.setOption(option, true)
  window.addEventListener('resize', function () {
    device.resize()
  })
}

export default deviceLife
